﻿package mortal.game.view.guildNew.member
{
    import Message.Game.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.game.view.copy.crossMainCity.mainCityPosition.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.platform.platformTencent.*;
    import mortal.mvc.core.*;

    public class GuildNewMemberCell extends GCellRenderer
    {
        protected var _txtMemberName:GTextFiled;
        protected var _txtPosition:GTextFiled;
        protected var _txtFightPower:GTextFiled;
        protected var _txtLevel_Career:GTextFiled;
        protected var _txtTodayContribution:GTextFiled;
        protected var _txtTotalContribution:GTextFiled;
        protected var _txtActives:GTextFiled;
        protected var _txtState:GTextFiled;
        protected var _line:ScaleBitmap;
        protected var _vipIcon:GImageBitmap;
        protected var _yellowIcon:GImageBitmap;
        private var _txtFindingTalent:GButton;
        private var _isSelected:Boolean = false;
        private var _bgSelected:ScaleBitmap;
        private var _bmpVip:GBitmap;
        private var _isSelfMembers:Boolean;

        public function GuildNewMemberCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._txtMemberName = UIFactory.gTextField("", 158, 4, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._txtPosition = UIFactory.gTextField("", 66, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._txtFightPower = UIFactory.gTextField("8561611351", 273, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._txtLevel_Career = UIFactory.gTextField("", 378, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._txtTodayContribution = UIFactory.gTextField("0", 454, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._txtTotalContribution = UIFactory.gTextField("123", 518, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._txtActives = UIFactory.gTextField("100", 584, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._txtState = UIFactory.gTextField("", 652, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._line = UIFactory.bg(-11, 29, 777, 1, this, ImagesConst.SplitLine);
            this._vipIcon = UIFactory.gImageBitmap("vipSmallIcon_9.png", 3, 6, this);
            this._yellowIcon = UIFactory.gImageBitmap("qqYellowYearVipSmallIcon_3.png", 46, 8, this);
            this._yellowIcon.visible = false;
            this._txtFindingTalent = UIFactory.gButton("" + Language.getString(71501), 648, 3, 50, 20);
            this._bgSelected = UIFactory.bg(0, 0, 745, 30, this, "selectFilter");
            this.update();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._isSelfMembers = false;
            this._txtFindingTalent = null;
            this._txtMemberName = null;
            this._txtPosition = null;
            this._txtFightPower = null;
            this._txtLevel_Career = null;
            this._txtTodayContribution = null;
            this._txtTotalContribution = null;
            this._txtActives = null;
            this._txtState = null;
            this._line = null;
            this._vipIcon = null;
            this._yellowIcon = null;
            this._bgSelected = null;
            return;
        }// end function

        public function update() : void
        {
            this.updateForSelfMembers();
            return;
        }// end function

        public function updateForSelfMembers() : void
        {
            this._isSelfMembers = true;
            this._txtState.visible = true;
            this._txtFindingTalent.visible = false;
            return;
        }// end function

        public function updateForFindTalentMembers() : void
        {
            this._isSelfMembers = false;
            this._txtState.visible = false;
            this._txtFindingTalent.visible = true;
            this._txtFindingTalent.configEventListener(MouseEvent.CLICK, this.onFindingTalent);
            return;
        }// end function

        private function onFindingTalent(event:MouseEvent) : void
        {
            var memberInfo:SGuildMember;
            var onCloseHandler:Function;
            var e:* = event;
            onCloseHandler = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_INVITE, {id:memberInfo.miniPlayer.entityId.id, type:EInviteMode._EInviteForDigMember}));
                }
                return;
            }// end function
            ;
            e.stopImmediatePropagation();
            if (Cache.instance.guild.selfGuildInfo.memberList.length >= Cache.instance.guild.selfGuildInfo.baseInfo.maxPlayerNum)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71502));
                return;
            }
            memberInfo = this._txtFindingTalent.Data as SGuildMember;
            if (!memberInfo.miniPlayer.online)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71503));
                return;
            }
            if (Cache.instance.guild.selfGuildInfo.baseInfo.resource < GameConst.TDigGuildMemberResoureCost)
            {
                MsgManager.showRollTipsMsg(Language.getString(70541));
                return;
            }
            Alert.show(Language.getStringByParam(70540, GameConst.TDigGuildMemberResoureCost), null, Alert.OK | Alert.CANCEL, null, onCloseHandler);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:* = param1 as SGuildMember;
            PlayerMenuRegister.UnRegister(this);
            if (_loc_2.miniPlayer.online)
            {
                if (!MainCityAppointSmallWin.isViewShow)
                {
                    PlayerMenuRegister.Register(this, _loc_2.miniPlayer, PlayerMenuConst.GuildMemberOnlineOpMenu);
                }
                var _loc_3:* = GuildUtil.MemberOnlineColor;
                this._txtState.textColor = GuildUtil.MemberOnlineColor;
                var _loc_3:* = _loc_3;
                this._txtActives.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTotalContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTodayContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtLevel_Career.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtFightPower.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtPosition.textColor = _loc_3;
                this._txtMemberName.textColor = _loc_3;
            }
            else
            {
                if (!MainCityAppointSmallWin.isViewShow)
                {
                    PlayerMenuRegister.Register(this, _loc_2.miniPlayer, PlayerMenuConst.GuildMemberOnlineOpMenu);
                }
                var _loc_3:* = GuildUtil.MemberOfflineColor;
                this._txtState.textColor = GuildUtil.MemberOfflineColor;
                var _loc_3:* = _loc_3;
                this._txtActives.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTotalContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtTodayContribution.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtLevel_Career.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtFightPower.textColor = _loc_3;
                var _loc_3:* = _loc_3;
                this._txtPosition.textColor = _loc_3;
                this._txtMemberName.textColor = _loc_3;
            }
            this._txtMemberName.text = _loc_2.miniPlayer.name;
            this._txtPosition.text = GameDefConfig.instance.getItem("EGuildPostion", _loc_2.position).text;
            if (_loc_2.miniPlayer.online)
            {
                this._txtPosition.textColor = parseInt(GameDefConfig.instance.getItem("EGuildPostion", _loc_2.position).text1.split("#")[1], 16);
            }
            this._txtLevel_Career.text = "lv." + _loc_2.miniPlayer.level + "." + GameDefConfig.instance.getItem("ECareer", _loc_2.miniPlayer.career).text;
            this._txtFightPower.text = _loc_2.miniPlayer.combat.toString();
            this._txtTodayContribution.text = _loc_2.contributionDay.toString();
            this._txtTotalContribution.text = _loc_2.totalContribution.toString();
            this._txtActives.text = _loc_2.activity.toString();
            if (_loc_2.miniPlayer.online)
            {
                this._txtActives.textColor = GlobalStyle.colorChenUint;
            }
            this._txtState.text = _loc_2.miniPlayer.online ? ("" + Language.getString(71504)) : (GuildUtil.getMemberOfflineState(_loc_2.lastLogoutDt));
            this._txtFindingTalent.Data = _loc_2;
            if (!this._isSelfMembers)
            {
                this._txtFindingTalent.visible = true;
            }
            if (_loc_2.position >= EGuildPosition._EGuildPresbyter)
            {
                this._txtFindingTalent.visible = false;
            }
            if (_loc_2.miniPlayer.VIP > 0)
            {
                this._vipIcon.visible = true;
                this._vipIcon.imgUrl = GameDefConfig.instance.getVipLevelIconUrl(_loc_2.miniPlayer.VIP, 1);
            }
            else
            {
                this._vipIcon.visible = false;
            }
            this.updateQQYellowGold(_loc_2);
            return;
        }// end function

        private function updateQQYellowGold(param1:SGuildMember) : void
        {
            var _loc_2:String = null;
            if (PlatformConst.isQQ() == false)
            {
                this._yellowIcon.visible = false;
                this._vipIcon.x = 35;
                return;
            }
            if (PlatformConst.isQQ() && param1.miniPlayer.proxyLevel)
            {
                _loc_2 = param1.miniPlayer.proxyLevel;
                if (_loc_2)
                {
                    this._yellowIcon.visible = true;
                    this._yellowIcon.imgUrl = PlatformTencentUtil.getQQVipIconUrl(_loc_2);
                }
                else
                {
                    this._yellowIcon.visible = false;
                }
            }
            else
            {
                this._yellowIcon.visible = false;
            }
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            this._isSelected = param1;
            if (this._isSelected)
            {
                this._bgSelected.visible = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildMemberSelect, this._txtFindingTalent.Data as SGuildMember));
            }
            else
            {
                this._bgSelected.visible = false;
            }
            return;
        }// end function

    }
}
